package com.kingdee.openimport.patch_service.service.impl;

import com.kingdee.openimport.patch_service.dao.PatchRepository;
import com.kingdee.openimport.patch_service.enume.PatchType;
import com.kingdee.openimport.patch_service.model.Patch;
import com.kingdee.openimport.patch_service.service.IPatchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by Niki on 2018/4/21 11:17
 */
@Service
public class PatchServiceImpl implements IPatchService {
    @Resource
    PatchRepository patchRepository;

    @Override
    public void create(Patch patch) {
        patchRepository.save(patch);
        flushPatchCache(patch.getVersion());
    }

    @Override
    public List<Patch> findByVersion(String version) {
        return patchRepository.findByVersion(version);
    }

    @Override
    public List<Patch> findIdAndClassNameByVersionAndType(String version, PatchType type) {
        return patchRepository.findIdAndClassNameByVersionAndType(version, type.name());
    }

    /**
     * 刷新补丁的缓存
     * 因为插入时并发量不大，因此此处每次插入都更新
     */
    private void flushPatchCache(String version) {

    }
}
